﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;

namespace CodeTop.CodeTop
{
    public class Solution67
    {
        public string AddBinary(string a, string b)
        {
            int lena=a.Length;
            int lenb=b.Length;
            int i = lena - 1;
            int j = lenb - 1;
            IList<int> list = new List<int>();

            int next = 0;
            while (i >=0&& j>=0)
            {

                char cura = a[i];
                char curb = b[j];

                int numa= int.Parse(cura.ToString());
                int numb= int.Parse(curb.ToString());
                int sum= next+numa + numb;
                int cur = sum % 2;
                next = sum / 2;
                Console.WriteLine(cur);
                list.Add(cur);
                i--;
                j--;
            }
           
            if (i == -1)
            {
               
                while (j >= 0)
                {
                    char curb = b[j];


                    int numb = int.Parse(curb.ToString());
                    int sum = next + numb;
                    int cur = sum % 2;
                    next = sum / 2;
                    list.Add(cur);
                    j--;
                }
               
            }
            else
            {
               
                while (i >= 0)
                {
                    char cura = a[i];

                    int numa = int.Parse(cura.ToString());
                    int sum = next + numa;
                    int cur = sum % 2;
                    next = sum / 2;
                    list.Add(cur);
                    i--;
                }
               

            }
            if(next != 0)
            {
                list.Add(next);
                Console.WriteLine("nxet"+ next);
            }

            string res = "";
           
            for (int k=list.Count-1;k>=0;k--)
            {
                res +=list[k];
                Console.WriteLine(list[k]);
            }
            return res;

           

        }
    }

    class Program67
    {
        static void Main67(string[] args)
        {

            string a = "11";
            string b = "1";
            Solution67 solution = new Solution67();
            string res = solution.AddBinary(a, b);
            Console.WriteLine(res);

        }
    }
}
